package com.jago.servlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class PropertiesServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Properties properties = new Properties();
        ServletContext servletContext = this.getServletContext();
        InputStream stream = servletContext.getResourceAsStream("/WEB-INF/classes/db.properties");
        properties.load(stream);
        String username = properties.getProperty("username");
        String pwd = properties.getProperty("pwd");
        resp.getWriter().println(username + " " + pwd);
    }
}
